﻿#Region "IMPORTS"

Imports DAO

#End Region

Public Class FornecedorDao
    Inherits DAO(Of Fornecedor)


#Region "CONSTRUTOR(S)"

    Public Sub New()
        MyBase.New()
    End Sub

#End Region

#Region "METODOS ABSTRATOS"


    Protected Overrides Sub ValidarInsert(modelo As Fornecedor)

        Dim NHQL As String = "from Fornecedor where RazaoSocial  = '" & modelo.RazaoSocial & "'"
        Dim list As IList = Me.Find(NHQL)
        If list.Count > 0 Then
            Throw New Exception("Já existe uma Fornecedor com esse Nome")
        End If
    End Sub

    Protected Overrides Sub ValidarDelete(modelo As Fornecedor)
    End Sub

    Protected Overrides Sub ValidarUpdate(ByVal modelo As Fornecedor)

        Dim NHQL As String = "from Fornecedor as f where f.Nome  = '" & modelo.RazaoSocial & "' AND f.FornecedorId != " & modelo.FornecedorId
        Dim list As IList = Me.Find(NHQL)
        If list.Count > 0 Then
            Throw New Exception("Já existe uma Fornecedor com esse Nome")
        End If

    End Sub

#End Region
End Class
